package com.kun.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kun.dao.BookInfoDao;
import com.kun.dao.PutbookInfoDao;
import com.kun.entity.BookInfo;
import com.kun.entity.PutbookInfo;
import com.kun.entity.UserInfo;
import com.kun.entity.WorkInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class putBookInfoService {

    @Autowired
    private PutbookInfoDao putbookInfoDao;

    @Autowired
    private BookInfoDao bookInfoDao;

    public PutbookInfo findById(Integer putbookId) {
        return putbookInfoDao.selectByPrimaryKey(putbookId);
    }

    public Map<String, Object> selectByPage(Integer pageNum, Integer pageSize, PutbookInfo putbookInfo) {
        //通过PageHelper对象设定分页参数
        PageHelper.startPage(pageNum, pageSize);
        //当前页面的数据
        List<PutbookInfo> list = putbookInfoDao.findAll(putbookInfo);
        //创建PageInfo对象，并将当前页面数据传入，计算分页相关数据
        PageInfo<PutbookInfo> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("total", total);
        return map;
    }
    public List<PutbookInfo> exportExcel(PutbookInfo putbookInfo) {
        return putbookInfoDao.findAll(putbookInfo);
    }
    public int insertPutBook(PutbookInfo putbookInfo) {
       /* BookInfo bookInfo = new BookInfo();
        bookInfo.setPutbookName(putbookInfo.getPutbookName());
        BookInfo book = (BookInfo) bookInfoDao.findAll(bookInfo);
        int num=Integer.parseInt(book.getPutbookNum());
        System.out.println(num + putbookInfo.getPutbookNum());*/
        return putbookInfoDao.insert(putbookInfo);
    }
    public int updatePutBook(PutbookInfo putbookInfo){
        return putbookInfoDao.updateByPrimaryKeySelective(putbookInfo);
    }
    public int deletePutBook(Integer[] putbookIds){return  putbookInfoDao.batchDelete(putbookIds);}
}
